#pragma once
#include "Camera.h"
#include "RenderTarget.h"

#include <memory>
class GLFWwindow;

namespace Umikaze::Core {

class Window {
private:
  static bool keys[1024];
  static bool keysPressed[1024];

  static void framebuffer_size_callback(GLFWwindow *window, int width,
                                        int height);

  static void mouse_callback(GLFWwindow *window, double xpos, double ypos);

  static void scroll_callback(GLFWwindow *window, double xoffset,
                              double yoffset);

  static void keyborad_callback(GLFWwindow *window, int key, int scancode,
                                int action, int mode);

  static void DoCameraMove(float deltaTime);

  void changePixelSize(int width, int height) {
    _pixelWidth = width;
    _pixelHeight = height;
    gDefaultCamera->_aspect = getAspect();
  }

public:
  bool init(int width, int height);

  bool shouldClose();

  void startDraw();

  void endDraw();

  float getAspect() { return _pixelWidth / float(_pixelHeight); }

  int getPixelWidth() { return _pixelWidth; }

  int getPixelHeight() { return _pixelHeight; }

  int getWidth() { return _width; }

  int getHeight() { return _height; }

  void setWindowSize(int width, int height);

  ~Window();

  const static std::unique_ptr<Window> &instance() {
    if (!_instance) {
      _instance = std::make_unique<Window>();
    }
    return _instance;
  }

private:
  GLFWwindow *_window;
  int _width;
  int _height;
  int _pixelWidth;
  int _pixelHeight;
  float _deltaTime;
  float _lastFrame;
  static std::unique_ptr<Window> _instance;
};

} // namespace Umikaze::Core
